package com.stork.sms.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.stork.sms.R;
import com.stork.sms.service.all.ServiceMethods;
import com.stork.sms.utilities.SharedPreference;

public class Splash extends Activity{
	public static final String LOGIN_ID="username";
	public static final String PASSWORD="password";
	String username,password;
	ServiceMethods servicecalllogin;
	Thread logoTimer;
	String response=null;
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splash);
//	String link=getIntent().getStringExtra("links");
//	AlertDialog.Builder adb = new AlertDialog.Builder(this);		
//	adb.setTitle("STORK SYSTEMS");		
////	adb.setIcon(R.drawable.ss);
//	adb.setMessage("Welcome  "+link);		
//	adb.setPositiveButton("Ok", null);
//	adb.show();
	Thread logoTimer = new Thread() {
        public void run(){
            try{
                int logoTimer = 0;
                while(logoTimer < 3000){
                    sleep(100);
                    logoTimer = logoTimer +100;
                };
               username=SharedPreference.readString(getApplicationContext(), LOGIN_ID, "");
                password=SharedPreference.readString(getApplicationContext(), PASSWORD, "");
                System.out.println("splash username"+username);
                System.out.println("splash password"+password);
                if(username!=""&&password!="")
                {
                	ServiceMethods sm=new ServiceMethods();
                	response=sm.Studendloginid(username, password);
        			
        			Log.d("splash response result", response);
        		
        			if(response.equals("111"))
        			{	
        				
        				Intent i=new Intent(getApplicationContext(),GridHomeMenuActivity.class);
        				startActivity(i);
        				
        			}else if(response.equals("444"))
        			{
        				
        				Toast.makeText(getApplicationContext(), "Invalid Valid User ", Toast.LENGTH_SHORT).show();
        				
        				
        				
        			}
                	
                }
                
                else{
                Intent i=new Intent(Splash.this,Login.class);
//				i.putExtra("li", link);
				startActivity(i);
                }
            }
             
            catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
             
            finally{
                finish();
            }
        }
    };
     
    logoTimer.start();
}

}
